package com.example.math_exam.MVC.acttivity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.math_exam.MVC.BaseActivity;
import com.example.math_exam.MVC.EnterAdapter;
import com.example.math_exam.R;
import com.example.math_exam.ShopEntitiy;

import java.util.ArrayList;
import java.util.List;

public class EnterActivity extends BaseActivity {

    private ArrayList<ShopEntitiy> list;

    private ImageView mEnterBack;
    private TextView mEnterPrice;
    private TextView mEnterEnter;
    private RecyclerView mEnterRecycler;
    private EnterAdapter adapter;



    @Override
    protected int getLayoutID() {
        return R.layout.activity_enter;
    }

    @Override
    protected void initActivity() {

        list = (ArrayList<ShopEntitiy>) getIntent().getSerializableExtra("list");

        mEnterBack = f(R.id.enter_back);
        mEnterPrice = f(R.id.enter_price);
        mEnterEnter = f(R.id.enter_enter);
        mEnterRecycler = f(R.id.enter_recycler);
        adapter = new EnterAdapter(R.layout.item_enter_list);
    }

    @Override
    protected void setOperation() {

        mEnterRecycler.setLayoutManager( new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        mEnterRecycler.setAdapter(adapter);
        adapter.setNewData( list);

        getPrice();
    }

    private void getPrice() {

        List<ShopEntitiy> data = adapter.getData();

        if( data == null || data.size() < 1) return;
        float price = 0;
        for (ShopEntitiy datum : data) {
            price = datum.getNum() * datum.getPrice();
        }

        mEnterPrice.setText( "" + price) ;
    }

    @Override
    protected void setListener() {

    }
}
